package view;

import ucm.User;

import javax.swing.*;
import java.awt.*;

/**
 * Author: Adam Scarr
 * Date: 25/03/2009
 * Time: 10:51:56 PM
 */
public class RegistrationUI extends JFrame {
    private JTextField username;
    private JPasswordField password;
    private JTextField firstName;
    private JTextField lastName;
    private JTextField homeAddress;
    private JTextField mailingAddress;
    private JTextField contactPhone;
    private JTextField contactEmail;
    private JButton register;
    private JButton cancel;

    public static void main(String[] args) {
        new RegistrationUI();
    }

    public void insertInto(User user) {
        user.setFirstName(firstName.getText());
        user.setLastName(lastName.getText());
        user.setHomeAddress(homeAddress.getText());
        user.setMailingAddress(mailingAddress.getText());
        user.setContactPhone(contactPhone.getText());
        user.setContactEmail(contactEmail.getText());
    }

    public RegistrationUI() {
        username = new JTextField();
        password = new JPasswordField();
        firstName = new JTextField();
        lastName = new JTextField();
        homeAddress = new JTextField();
        mailingAddress = new JTextField();
        contactPhone = new JTextField();
        contactEmail = new JTextField();
        register = new JButton("Register");
        cancel = new JButton("Cancel");

        JTextArea description = new JTextArea("You must register before using this software. Please fill in the following details");
        description.setLineWrap(true);
        description.setColumns(20);
        description.setRows(3);
        description.setMaximumSize(new Dimension(100,0));
        add(description, BorderLayout.NORTH);

        JPanel userDetails = new JPanel();
        userDetails.setLayout(new GridLayout(9, 2));
        add(userDetails, BorderLayout.CENTER);

        userDetails.add(new JLabel("Username"));
        userDetails.add(username);
        userDetails.add(new JLabel("Password"));
        userDetails.add(password);
        userDetails.add(new JLabel("First Name"));
        userDetails.add(firstName);
        userDetails.add(new JLabel("Last Name"));
        userDetails.add(lastName);
        userDetails.add(new JLabel("Home Address"));
        userDetails.add(homeAddress);
        userDetails.add(new JLabel("Mailing Address"));
        userDetails.add(mailingAddress);
        userDetails.add(new JLabel("Phone"));
        userDetails.add(contactPhone);
        userDetails.add(new JLabel("Email"));
        userDetails.add(contactEmail);
        userDetails.add(register);
        userDetails.add(cancel);

        pack();
        setVisible(true);
    }


}
